﻿using MES.Desktop.Entities;
using MES.Desktop.IDataAccess;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MES.Desktop.DataAccess
{
    public class DepartAccess : WebAccess, IDepartAccess
    {
        public DepartAccess(GlobalValues globalValues)
            : base(globalValues)
        {
        }
        public string CheckName(string name, int id)
        {
            string uri = $"/api/baseinfo/depart/check/{id}/{name}";
            return this.Get(uri);
        }

        public string DeleteDepart(string ids)
        {
            string uri = $"/api/baseinfo/depart/delete/ids";
            StringContent content = new StringContent(ids);
            content.Headers.ContentType =
                new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return this.Post(uri, content);
        }

        public string GetAllDeparts(string key)
        {
            key = string.IsNullOrEmpty(key) ? "none" : key;
            string uri = $"/api/baseinfo/depart/{key}";
            return this.Get(uri);
        }

        public string UpdateDepart(string menuJson)
        {
            string uri = "api/baseinfo/depart/update";

            StringContent content = new StringContent(menuJson);
            content.Headers.ContentType =
                new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

            return this.Post(uri, content);
        }
    }
}
